package com.cuit.bysj.dao;

import java.util.List;

import com.cuit.bysj.entities.Appraise;
import com.cuit.bysj.entities.State;
import com.cuit.bysj.entities.User;

public class UserDao extends BaseDao {

	@SuppressWarnings("unchecked")
	/*
	 * 登录时根据账号密码进行用户查找
	 */
	public User findUser(String name, String password) {

		String hql = "from User u where u.name=" + "'" + name + "'" + " and u.password=" + "'" + password + "'";

		List<User> list = getSession().createQuery(hql).list();

		if (list.size() > 0) {
			return (User) list.get(0);
		}

		return null;
	}

	@SuppressWarnings("rawtypes")
	public List loadlist(String hql) {

		List list = getSession().createQuery(hql).list();

		return list;
	}

	public void initState() {
		State s = getByID(1);
		if (s == null) {
			s = new State();
			s.setId(1);
			s.setState(false);
			getSession().save(s);
		}
	}

	public void addTable(Appraise a) {
		getSession().save(a);
	}

	public void update(User user) {
		getSession().update(user);
	}

	// 查询单个实体对象
	public State getByID(Integer id) {
		return (State) getSession().get(State.class, id);
	}
	
	// 查询单个实体对象
		public User getserByID(Integer id) {
			return (User) getSession().get(User.class, id);
		}
}
